﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;

/// <summary>
/// CategoryActions 的摘要说明
/// </summary>
public class CategoryActions
{
    public static Dictionary<int, string> CategoryType
    {
        get
        {
            Dictionary<int, string> type = new Dictionary<int, string>();
            type.Add(1, "About");
            type.Add(2, "Prodect");
            type.Add(3, "News");
            type.Add(4, "Jobs");
            type.Add(5, "Contact");
            type.Add(6, "Case");
            return type;
        }
    }
    public Dictionary<string, int> Type
    {
        get
        {
            Dictionary<string, int> type = new Dictionary<string, int>();
            type.Add("About", 1);
            type.Add("Product", 2);
            type.Add("News", 3);
            type.Add("Job", 4);
            type.Add("Contact", 5);
            type.Add("Case", 6);
            return type;
        }
    }
    public DataTable GetByID(int id)
    {
        string sql = "select * from [temple_Category] where [ID] = @id and [IsDel] = 0";
        SqlParameter[] pars = { new SqlParameter("@id", id) };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetAll(int parid, string lang = "chs")
    {
        string sql = "select * from [temple_Category] where [ParentID] = @parid and [Language] = @lang and IsDel = 0 order by SortID";
        SqlParameter[] pars = {
            new SqlParameter("@parid",parid),
            new SqlParameter("@lang",lang)
        };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetAll(string flag, string lang = "chs")
    {
        string sql = "select * from [temple_Category] where [Flag] = @flag and [Language] = @lang and IsDel = 0 order by SortID";
        SqlParameter[] pars = {
            new SqlParameter("@flag",flag),
            new SqlParameter("@lang",lang)
        };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetAll(int parid, int flag, string lang = "chs")
    {
        string sql = "select * from [temple_Category] where [Flag] = @flag and [ParentID] = @parid and [Language] = @lang and IsDel = 0 order by SortID";
        SqlParameter[] pars = {
            new SqlParameter("@parid",parid),
            new SqlParameter("@flag",flag),
            new SqlParameter("@lang",lang)
        };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetList(int parid)
    {
        string sql = "select * from [temple_Category] where [ParentID] = @parid and IsDel = 0 order by SortID";
        SqlParameter[] pars = { new SqlParameter("@parid", parid) };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetList(int parid, int flag)
    {
        string sql = "select * from [temple_Category] where [Flag] = @flag and [ParentID] = @parid and IsDel = 0 order by SortID";
        SqlParameter[] pars = {
            new SqlParameter("@parid",parid),
            new SqlParameter("@flag",flag)
        };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetList(string flag)
    {
        string sql = "select * from [temple_Category] where [Name] = @flag and IsDel = 0 order by SortID";
        SqlParameter[] pars = { new SqlParameter("@flag", flag) };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetByType(int type, string lang)
    {
        string sql = "select * from [temple_Category] where [Type] = @type and [Language] = @lang and IsDel = 0 order by SortID";
        SqlParameter[] pars = { 
            new SqlParameter("@type", type),
            new SqlParameter("@lang", lang)
        };
        return DBHelper.GetDataTable(sql, pars);
    }
    public DataTable GetByType(int type)
    {
        string sql = "select * from [temple_Category] where [Type] = @type and IsDel = 0 order by SortID";
        SqlParameter[] pars = { 
            new SqlParameter("@type", type)
        };
        return DBHelper.GetDataTable(sql, pars);
    }

}

public enum CategoryFlag : int
{
    nav = 1,
    type = 2,
    banner = 3,
}
